home *** CD-ROM | disk | FTP | other *** search
-
- (eval '(sequence
- (define data-corrente (read-number "data corrente:"))
- (define (biblio-loop)
- (newline)
- (display "Biblio -->")
- (user-print (eval (read) user-biblio-environment)))
- (define user-biblio-environment (make-environment))
- (define (user-print exp)
- (cond ((archivio? exp)
- (let ((el ((get-arc exp) 'read (get-pos exp))))
- (cond ((eq? el 'out-of-range)
- (writeln "Archivio vuoto"))
- ((eq? (get-type exp) 'utente)
- (writeln "Catalogo " (get-sigla exp))
- (output-utente el))
- ((eq? (get-type exp) 'volume)
- (writeln "Schedario " (get-sigla exp))
- (output-volume el))
- (else (error "Archivio di tipo sconosciuto" exp)))))
- (else (print exp))))
- (define (make-schedario size sigla)
- (make-archivio size
- utente<=?
- utente=?
- (list 'utente sigla)))
- (define (make-catalogo size sigla)
- (make-archivio size
- volume-autore<=?
- volume-autore=?
- (list 'volume sigla 0)))
- (define (crea)
- (define tipo (begin (display "Tipo di archivio : ")
- (read)))
- (define val (read-number "Dimensione archivio : "))
- (define sigla (read-string "Codice archivio : "))
- (cond ((eq? tipo 'utente)
- (make-biblio (make-schedario val sigla) 0))
- ((eq? tipo 'volume)
- (make-biblio (make-catalogo val sigla) 0))
- (else (error "Tipo di archivio sconosciuto." tipo))))
- (define (prossimo arc)
- (if (< (get-pos arc) (-1+ ((get-arc arc) 'last-el nil)))
- (begin (set-pos! arc (1+ (get-pos arc)))
- arc)
- (begin (writeln "Ultimo elemento")
- arc)))
- (define (precedente arc)
- (if (> (get-pos arc) 0)
- (begin (set-pos! arc (-1+ (get-pos arc)))
- arc)
- (begin (writeln "Primo elemento")
- arc)))
- (define (primo arc)
- (set-pos! arc 0)
- arc)
- (define (ultimo arc)
- (set-pos! arc (-1+ ((get-arc arc) 'last-el nil)))
- arc)
- (define (salva arc name)
- ((get-arc arc) 'ch-us-da (get-data arc))
- ((get-arc arc) 'save name))
- (define (carica name)
- (define arc (make-archivio 0 nil nil nil))
- (define res (arc 'load name))
- (define tipo (car (arc 'us-data nil)))
- (if (eq? res 'done)
- (begin (cond ((eq? tipo 'utente)
- (arc 'ch-ord
- (cons utente<=? utente=?)))
- ((eq? tipo 'volume)
- (arc 'ch-ord
- (cons volume-autore<=? volume-autore=?)))
- (else (error "Archivio di tipo sconosciuto" arc)))
- (make-biblio arc 0))
- (error "Errore durante l'apertura del file" res)))
-
- (define (make-collocazione sigla pos)
- (string-append sigla (integer->string pos 10)))
- (define (aggiungi arc)
- (define tipo nil)
- (define elem nil)
- (if (not (archivio? arc))
- (error "L'argomento di aggiungi deve essere un archivio" arc))
- (set! tipo (get-type arc))
- (cond ((eq? tipo 'utente)
- (set! elem (input-utente)))
- ((eq? tipo 'volume)
- (set! elem (input-volume))
- (set-collocazione-L! (get-libro-V elem)
- (make-collocazione (get-sigla arc)
- (get-next-col arc)))
- (set-next-col! arc (1+ (get-next-col arc))))
- (else (error "Archivio sconosciuto" tipo)))
- (if (conferma? "I dati sono corretti? ")
- (if (eq? ((get-arc arc) 'add-ord elem) 'full)
- (writeln "Archivio pieno --- non aggiunto")))
- arc)
- (define (cancella arc)
- (if (not (archivio? arc))
- (error "L'argomento di cancella deve essere un archivio" arc))
- (user-print arc)
- (if (conferma? "Vuoi cancellare questo elemento? ")
- (if (eq? ((get-arc arc) 'del-el (get-pos arc)) 'done)
- (begin (if (and (>= (get-pos arc) ((get-arc arc) 'last-el nil))
- (> (get-pos arc) 0))
- (set-pos! arc (-1+ (get-pos arc))))
- (writeln "Cancellato"))
- (writeln "Non posso cancellare")))
- arc)
- (define (cataloga arc)
- (define tipo nil)
- (define archivio nil)
- (if (not (archivio? arc))
- (error "L'argomento di cataloga deve essere un archivio" arc))
- (set! archivio (get-arc arc))
- (set! tipo (get-type arc))
- (do ((done #f)
- (elem nil))
- (done (writeln "Sto ordinando l'archivio")
- (archivio 'sort nil))
- (writeln "Inserisci i dati")
- (cond ((eq? tipo 'utente) (set! elem (input-utente)))
- ((eq? tipo 'volume) (set! elem (input-volume)))
- (else (error "Archivio di tipo sconosciuto" tipo)))
- (if (conferma? "I dati sono corretti? ")
- (begin (if (eq? tipo 'volume)
- (begin (set-collocazione-L! (get-libro-V elem)
- (make-collocazione (get-sigla arc)
- (get-next-col arc)))
- (set-next-col! arc (1+ (get-next-col arc)))))
- (if (eq? (archivio 'add elem) 'full)
- (writeln "Archivio pieno -- non aggiunto"))))
- (if (conferma? "Fine catalogazione? ")
- (set! done #t))))
- (define (cerca arc)
- (define tipo nil)
- (define found nil)
- (if (not (archivio? arc))
- (error "L'argomento di ricerca deve essere un archivio" arc))
- (set! tipo (get-type arc))
- (cond ((eq? tipo 'utente)
- (set! found (cerca-utente (get-arc arc))))
- ((eq? tipo 'volume)
- (set! found (cerca-volume (get-arc arc))))
- (else (error "Archivio sconosciuto" tipo)))
- (if (number? found)
-
- (set-pos! arc found))
- arc)
-
- (define (cerca-utente archivio)
- (do ((elem nil)
- (found nil)
- (done #f))
- (done found)
- (writeln "ricerca Utenti")
- (set! elem (make-utente (input-persona) nil))
- (set! found (archivio 'search elem))
- (if (eq? found 'not-found)
- (writeln "Non trovato")
- (begin (set! elem (archivio 'read found))
- (writeln "Trovato:")
- (output-utente elem)
- (output-prestiti (get-prestiti-U elem))))
- (if (conferma? "Fine ricerca? ")
- (set! done #t))))
-
- (define (ric-seq arc pos elem)
- (define el (arc 'read pos))
- (cond ((eq? el 'out-of-range) nil)
- ((volume=? elem el)
- (cons el (ric-seq arc (1+ pos) elem)))
- ((volume-autore<=? el elem) nil)
- (else (ric-seq arc (1+ pos) elem))))
-
- (define (cerca-volume archivio)
- (do ((data nil)
- (libro nil)
- (elem nil)
- (el-lis nil)
- (found nil)
- (done #f))
- (done found)
- (writeln "ricerca Volumi")
- (set! libro (input-libro))
- (set! data (read-number "Data:"))
- (set! elem (make-volume libro data nil))
- (set! found (archivio 'search elem))
- (if (eq? found 'not-found)
- (writeln "Nessun volume con questi autori")
- (begin (writeln "Autori presenti nell'archivio.")
- (set! el-lis (ric-seq archivio found elem))
- (if (null? el-lis)
- (writeln "Nessun volume con questo titolo e data di pubblicazione")
- (begin (writeln "Trovate "(length el-lis) " copie del libro")
- (for-each output-volume el-lis)))))
- (if (conferma? "Fine ricerca? ")
- (set! done #t))))
-
- (define (prestito volume utente)
- (define vol nil)
- (define ute nil)
- (define da-re nil)
- (if (or (not (archivio? volume))
- (not (eq? (get-type volume) 'volume)))
- (error "Il primo argomento di prestito deve essere un archivio volumi" nil))
- (if (or (not (archivio? utente))
- (not (eq? (get-type utente) 'utente)))
- (error "Il secondo argomento di prestito deve essere un archivio utenti" nil))
- (set! vol ((get-arc volume) 'read (get-pos volume)))
- (set! ute ((get-arc utente) 'read (get-pos utente)))
- (if (eq? ute 'out-of-range)
- (writeln "Archivio utenti vuoto"))
- (if (eq? vol 'out-of-range)
- (writeln "Archivio volumi vuoto"))
- (set! da-re (get-data-res-D (get-last-pres-V vol)))
- (if (= (length (get-prestiti-U ute)) 3)
- (error "L'utente ha gia` tre libri in prestito" nil))
- (if (and (not (data? da-re)) da-re)
- (error "Il volume e` gia` in prestito" nil))
- (add-prestito-V! vol (make-data data-corrente (get-persona-U ute)))
- (add-prestiti-U! (make-prestito (get-libro-V vol)
- (make-data data-corrente nil))
- ute)
- utente)
-
- (define (restituzione volume utente)
- (define vol nil)
- (define ute nil)
- (define prest nil)
- (define pr-L nil)
- (if (or (not (archivio? volume))
- (not (eq? (get-type volume) 'volume)))
- (error "Il primo argomento di restituzione deve essere un archivio volumi" nil))
- (if (or (not (archivio? utente))
- (not (eq? (get-type utente) 'utente)))
- (error "Il secondo argomento di restituzione deve essere un archivio utenti" nil))
- (set! vol ((get-arc volume) 'read (get-pos volume)))
- (set! ute ((get-arc utente) 'read (get-pos utente)))
- (if (eq? ute 'out-of-range)
- (writeln "Archivio utenti vuoto"))
- (if (eq? vol 'out-of-range)
- (writeln "Archivio volumi vuoto"))
- (get-collocazione-L (get-libro-V vol))
- (set! prest (find-pres-U (get-collocazione-L (get-libro-V vol))
- ute))
- (if (null? prest)
- (error "Il libro non e` in prestito a questo utente" utente))
- (set! pr-L (get-pres-U prest ute))
- (rem-pres-U! prest ute)
- (set-data-res-D! (get-data-P pr-l) data-corrente)
- (add-restituiti-U! pr-l ute)
- (set-data-res-D! (get-last-pres-V vol) data-corrente)
- utente)
- (define esci scheme-reset)
-
- (define (stampa-archivio arc)
- (define tipo nil)
- (if (not (archivio? arc))
- (error "L'argomento di stampa-archivio deve essere un archivio" arc))
- (set! tipo (get-type arc))
- (cond ((eq? tipo 'utente)
- ((get-arc arc) 'for-each output-utente))
- ((eq? tipo 'volume)
- ((get-arc arc) 'for-each output-volume))
- (else (error "Archivio sconosciuto" tipo))))
-
- (define (stampa-prestiti-utente utente volume)
- (define ut nil)
- (if (or (not (archivio? utente))
- (not (eq? (get-type utente) 'utente)))
- (error "Il primo argomento di stampa-prestiti-utente deve essere un archivio utenti" nil))
- (if (or (not (archivio? volume))
- (not (eq? (get-type volume) 'volume)))
- (error "Il secondo argomento di stampa-prestiti-utente deve essere un archivio volumi" nil))
- (set! ut ((get-arc utente) 'read (get-pos utente)))
- (writeln "Libri attualmente in prestito all'utente:")
- (do ((prest (get-prestiti-U ut) (cdr prest))
- (found nil))
- ((null? prest))
- (set! found
- ((get-arc volume) 'search
- (make-volume (get-libro-P (car prest))
- nil
- nil)))
- (if found
- (output-volume ((get-arc volume) 'read found))
- (output-libro (get-libro-P (car prest))))))
- (define (stampa-prestiti-volume volume data)
- (if (or (not (archivio? volume))
- (not (eq? (get-type volume) 'volume)))
- (error "Il primo argomento di stampa-prestiti-volume deve essere un archivio volumi" nil))
- (if data
- ((get-arc volume) 'for-each
- (lambda (x)
- (define da-re (get-data-res-D (get-last-pres-V x)))
- (if (and da-re (not (data? da-re)))
- (if (and data
- (data<=? (get-data-pre-D (get-last-pres-V x)) data))
- (begin (output-volume x)
- (writeln "all'utente:")
- (output-persona da-re))))))
- ((get-arc volume) 'for-each
- (lambda (x)
- (define da-re (get-data-res-D (get-last-pres-V x)))
- (if (and da-re (not (data? da-re)))
- (begin (output-volume x)
- (writeln "all'utente:")
- (output-persona da-re)))))))
-
- ) biblioteca-environment)
-
-
-
- (define (biblioteca)
- (set! (fluid scheme-top-level)
- (access biblio-loop biblioteca-environment))
- (reset))
-